
import onFormBeforeEvent from '../request-functions/onFormBeforeEvent';
const batchAddSubTemplate = 'batchAddSub';
const batchAddSubTaleTemplate = 'batchAddSubTaleTemplate';
export default function(props, moduleId, key, value, oldValue) {
    const {
        pk_org,
        form: {
            getAllFormValue,
            setFormItemsDisabled
        },
        meta: {
            getMeta,
            setMeta
        },
        func_type
    } = this.props;

    let postData = {
        areaCode: this.state.currentForm,
        func_type: func_type,
        key: key, 
        model: getAllFormValue(batchAddSubTemplate),
        pk_org: pk_org
    };
    let template = getMeta();
    
    onFormBeforeEvent(postData)
        .then((res) => {
            if(res.success) {
                let {
                    editable,
                    refParam
                } = res.data;

                setFormItemsDisabled(batchAddSubTemplate, {
                    [key]: !editable
                });

                template[batchAddSubTemplate].items.map((item) => {
                    if(item.attrcode === key) {
                        item['queryCondition'] = refParam
                    }
                });
                setMeta(template);
            }
        });

    return true;
}
